package com.itheima.controller.backend;

import com.itheima.common.entity.Result;
import com.itheima.common.vo.BusinessReportData;
import com.itheima.common.vo.MemberReportVo;
import com.itheima.common.vo.SetmealStatistic;
import com.itheima.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/report")
@Slf4j
@Api(tags = "报表相关接口")
public class ReportController {
    @Autowired
    private ReportService reportService;

    /**
     * 会员数量统计
     * @return
     */
    @GetMapping("/getMemberReport")
    public Result getMemberReport() {
        log.info("getMemberReport");
        MemberReportVo memberReportVo = reportService.getMemberReport();
        return new Result(true, "查询成功", memberReportVo);
    }

    /**
     * 套餐占比统计
     *
     * @return
     */
    @GetMapping("/getSetmealReport")
    public Result getSetmealReport() {
        log.info("getSetmealReport");
        SetmealStatistic setmealStatistic = reportService.getSetmealReport();
        return new Result(true, "查询成功", setmealStatistic);
    }

    /**
     * 运营数据统计
     *
     * @return
     */
    @GetMapping("/getBusinessReportData")
    @ApiOperation("获取运营数据统计")
    public Result getBusinessReportData() {
        log.info("getBusinessReportData");
        BusinessReportData businessReportData = reportService.getBusinessReportData();
        if (businessReportData != null) {
            return new Result(true, "查询成功", businessReportData);
        }else{
            return new Result(false, "查询失败");
        }
    }

    /**
     * 导出运营数据
     * @return
     */
    @GetMapping("/exportBusinessReport")
    @ApiOperation("导出运营数据")
    public String exportBusinessReport() throws IOException {
        log.info("导出运营数据");
        reportService.exportBusinessReport();
        return "下载文件";

    }
}
